package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallMechanismProductMapper;
import org.linlinjava.litemall.db.domain.LitemallMechanismProduct;
import org.linlinjava.litemall.db.domain.LitemallMechanismProductExample;
import org.linlinjava.litemall.db.domain.LitemallUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LitemallMechanismProductService {
    @Resource
    private LitemallMechanismProductMapper mechanismProductMapper;

    public List<LitemallMechanismProduct> queryByGid(Integer gid) {
        LitemallMechanismProductExample example = new LitemallMechanismProductExample();
        example.or().andGoodsIdEqualTo(gid).andDeletedEqualTo(false);
        return mechanismProductMapper.selectByExample(example);
    }

    //    public LitemallMechanismProduct findById(Integer id) {
//        return mechanismProductMapper.selectByPrimaryKey(id);
//    }
//
//    public List<LitemallMechanismProduct> querySelective(Integer goodsId, Integer page, Integer size, String sort, String order) {
//        LitemallMechanismProductExample example = new LitemallMechanismProductExample();
//        LitemallMechanismProductExample.Criteria criteria = example.createCriteria();
//
//        if(goodsId != null){
//            criteria.andGoodsIdEqualTo(goodsId);
//        }
//        criteria.andDeletedEqualTo(false);
//
//        PageHelper.startPage(page, size);
//        return mechanismProductMapper.selectByExample(example);
//    }
//
//    public int countSelective(Integer goodsId, Integer page, Integer size, String sort, String order) {
//        LitemallMechanismProductExample example = new LitemallMechanismProductExample();
//        LitemallMechanismProductExample.Criteria criteria = example.createCriteria();
//
//        if(goodsId != null){
//            criteria.andGoodsIdEqualTo(goodsId);
//        }
//        criteria.andDeletedEqualTo(false);
//
//        return (int)mechanismProductMapper.countByExample(example);
//    }
//
//    public void updateById(LitemallMechanismProduct product) {
//        mechanismProductMapper.updateByPrimaryKeySelective(product);
//    }
//
//    public void deleteById(Integer id) {
//        mechanismProductMapper.logicalDeleteByPrimaryKey(id);
//    }
//
    public void add(LitemallMechanismProduct product) {
        mechanismProductMapper.insertSelective(product);
    }
//
//    public int count() {
//        LitemallMechanismProductExample example = new LitemallMechanismProductExample();
//        example.or().andDeletedEqualTo(false);
//
//        return (int)mechanismProductMapper.countByExample(example);
//    }
//
    public void deleteByGid(Integer gid) {
        LitemallMechanismProductExample example = new LitemallMechanismProductExample();
        example.or().andGoodsIdEqualTo(gid);
        mechanismProductMapper.logicalDeleteByExample(example);
    }
    //
//    public List<LitemallMechanismProduct> queryByIds(List<Integer> ids){
//        LitemallMechanismProductExample example = new LitemallMechanismProductExample();
//        example.or().andIdIn(ids);
//        return mechanismProductMapper.selectByExample(example);
//    }
//
    public List<LitemallMechanismProduct> queryByNum(){
        LitemallMechanismProductExample example = new LitemallMechanismProductExample();
        example.or().andDeletedEqualTo(false);
        return mechanismProductMapper.selectByExample(example);
    }
//
//    public List<LitemallMechanismProduct> queryByProductId(List<Integer> productIds){
//        LitemallMechanismProductExample example = new LitemallMechanismProductExample();
//        example.or().andIdIn(productIds);
//        return mechanismProductMapper.selectByExample(example);
//    }
    public void update(LitemallMechanismProduct product) {
        mechanismProductMapper.updateByPrimaryKeySelective(product);
    }
}
